home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / debug / Debug.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.5 KB  |  136 lines

  1. package com.google.analytics.debug
  2. {
  3.    import flash.events.KeyboardEvent;
  4.    import flash.ui.Keyboard;
  5.    
  6.    public class Debug extends Label
  7.    {
  8.       
  9.       public static var count:uint = 0;
  10.        
  11.       
  12.       private var _lines:Array;
  13.       
  14.       private var _preferredForcedWidth:uint = 540;
  15.       
  16.       private var _linediff:int = 0;
  17.       
  18.       public var maxLines:uint = 16;
  19.       
  20.       public function Debug(color:uint = 0, alignement:Align = null, stickToEdge:Boolean = false)
  21.       {
  22.          if(alignement == null)
  23.          {
  24.             alignement = Align.bottom;
  25.          }
  26.          super("","uiLabel",color,alignement,stickToEdge);
  27.          this.name = "Debug" + count++;
  28.          _lines = [];
  29.          selectable = true;
  30.          addEventListener(KeyboardEvent.KEY_DOWN,onKey);
  31.       }
  32.       
  33.       public function writeBold(message:String) : void
  34.       {
  35.          write(message,true);
  36.       }
  37.       
  38.       private function _getLinesToDisplay(direction:int = 0) : Array
  39.       {
  40.          var lines:Array = null;
  41.          var start:uint = 0;
  42.          var end:uint = 0;
  43.          if(_lines.length - 1 > maxLines)
  44.          {
  45.             if(_linediff <= 0)
  46.             {
  47.                _linediff += direction;
  48.             }
  49.             else if(_linediff > 0 && direction < 0)
  50.             {
  51.                _linediff += direction;
  52.             }
  53.             start = uint(_lines.length - maxLines + _linediff);
  54.             end = start + maxLines;
  55.             lines = _lines.slice(start,end);
  56.          }
  57.          else
  58.          {
  59.             lines = _lines;
  60.          }
  61.          return lines;
  62.       }
  63.       
  64.       private function onKey(event:KeyboardEvent = null) : void
  65.       {
  66.          var lines:Array = null;
  67.          switch(event.keyCode)
  68.          {
  69.             case Keyboard.DOWN:
  70.                lines = _getLinesToDisplay(1);
  71.                break;
  72.             case Keyboard.UP:
  73.                lines = _getLinesToDisplay(-1);
  74.                break;
  75.             default:
  76.                lines = null;
  77.          }
  78.          if(lines == null)
  79.          {
  80.             return;
  81.          }
  82.          text = lines.join("\n");
  83.       }
  84.       
  85.       override public function get forcedWidth() : uint
  86.       {
  87.          if(this.parent)
  88.          {
  89.             if(UISprite(this.parent).forcedWidth > _preferredForcedWidth)
  90.             {
  91.                return _preferredForcedWidth;
  92.             }
  93.             return UISprite(this.parent).forcedWidth;
  94.          }
  95.          return super.forcedWidth;
  96.       }
  97.       
  98.       public function write(message:String, bold:Boolean = false) : void
  99.       {
  100.          var inputLines:Array = null;
  101.          if(message.indexOf("") > -1)
  102.          {
  103.             inputLines = message.split("\n");
  104.          }
  105.          else
  106.          {
  107.             inputLines = [message];
  108.          }
  109.          var pre:String = "";
  110.          var post:String = "";
  111.          if(bold)
  112.          {
  113.             pre = "<b>";
  114.             post = "</b>";
  115.          }
  116.          for(var i:int = 0; i < inputLines.length; i++)
  117.          {
  118.             _lines.push(pre + inputLines[i] + post);
  119.          }
  120.          var lines:Array = _getLinesToDisplay();
  121.          text = lines.join("\n");
  122.       }
  123.       
  124.       public function close() : void
  125.       {
  126.          dispose();
  127.       }
  128.       
  129.       override protected function dispose() : void
  130.       {
  131.          removeEventListener(KeyboardEvent.KEY_DOWN,onKey);
  132.          super.dispose();
  133.       }
  134.    }
  135. }
  136.